﻿
@{
    ViewBag.Title = "修改字典值";
}
@model KTD.Web.Models.VD.DicCUD

<div class="x-body" id="saveResult" style="width:100%;">
    <div class="layui-form">
        @Html.HiddenFor(model => model.Id)
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>字典类型
                </label>
                <div class="layui-input-inline">
                    @Html.EnumDropDownListFor(n => n.DicType, new { @class = "layui-input" })
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>字典值
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(model => model.Value, new { @class = "layui-input" })
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>顺序
                </label>
                <div class="layui-input-inline">
                    @Html.TextBoxFor(model => model.Order, new { @class = "layui-input", @type = "number" })
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="L_email" class="layui-form-label">
                    <span class="x-red">*</span>状态
                </label>
                <div class="layui-input-inline">
                    @Html.CheckBoxFor(model => model.Enable, new { @class = "layui-input" })
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button id="btnAdd" class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </div>
</div>



@section scripts{
    <script>
        layui.use(['form', 'layer'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;

            //自定义验证规则
            form.verify({
                nikename: function (value) {
                    if (value.length < 5) {
                        return '昵称至少得5个字符啊';
                    }
                }
                , pass: [/(.+){6,12}$/, '密码必须6到12位']
                , repass: function (value) {
                    if ($('#L_pass').val() != $('#L_repass').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            //监听提交
            form.on('submit(add)', function (data) {
                var formdata = new FormData();
                formdata.append("Id", $("#Id").val());
                formdata.append("DicType", $("#DicType").val());
                formdata.append("Value", $("#Value").val());
                formdata.append("Order", $("#Order").val());
                formdata.append("Enable", $("#Enable").val());
                $.ajax({

                    url: "/Dic/Update",
                    type: "post",
                    data: formdata,
                    processData: false,    // 不处理数据
                    contentType: false,    // 不设置内容类型

                    success: function (data) {

                        //发异步，把数据提交给php
                        layer.alert("修改成功", { icon: 6 }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            parent.window.location.reload();
                        });
                    }
                })
                return false;
            });


        });

    </script>
}